/**
 * https://leetcode.com/problems/h-index/#/description
 */
package leetCode;

import java.util.Arrays;

/**
 * @author zhongfang
 *
 */
public class HIndex {
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int N=citations.length;
        int h=N;
        while (h>=1) {
			boolean goout=false;
			if(h==N){//不需要考虑左边
				goout=(citations[N-h]>=h);
			}else {
				goout=(citations[N-h-1]<=h&&citations[N-h]>=h);
			}
			if(goout){
				break;
			}
			h--;
		}
        return h;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}

}
